home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / tweak16b.zip / MISC / SETMODEX.ASM < prev    next >
Assembly Source File  |  1993-11-22  |  3KB  |  88 lines

  1. ; This file was taken from Michael Abrash' XSHARP package, a library
  2. ; for programming mode X (320x240x256).
  3.  
  4. ; Mode X (320x240, 256 colors) mode set routine. Works on all VGAs.
  5. ; C near-callable as:
  6. ;       void Set320x240Mode(void);
  7. ; Tested with TASM 2.0.
  8. ; Modified from public-domain mode set code by John Bridges.
  9.  
  10. SC_INDEX equ    03c4h   ;Sequence Controller Index
  11. CRTC_INDEX equ  03d4h   ;CRT Controller Index
  12. MISC_OUTPUT equ 03c2h   ;Miscellaneous Output register
  13. SCREEN_SEG equ  0a000h  ;segment of display memory in mode X
  14.  
  15.         .model  small
  16.         .data
  17. ; Index/data pairs for CRT Controller registers that differ between
  18. ; mode 13h and mode X.
  19. CRTParms label  word
  20.         dw      00d06h  ;vertical total
  21.         dw      03e07h  ;overflow (bit 8 of vertical counts)
  22.         dw      04109h  ;cell height (2 to double-scan)
  23.         dw      0ea10h  ;v sync start
  24.         dw      0ac11h  ;v sync end and protect cr0-cr7
  25.         dw      0df12h  ;vertical displayed
  26.         dw      00014h  ;turn off dword mode
  27.         dw      0e715h  ;v blank start
  28.         dw      00616h  ;v blank end
  29.         dw      0e317h  ;turn on byte mode
  30. CRT_PARM_LENGTH equ     (($-CRTParms)/2)
  31.  
  32.         .code
  33.         public  _Set320x240Mode
  34. _Set320x240Mode proc    near
  35.         push    bp      ;preserve caller's stack frame
  36.         push    si      ;preserve C register vars
  37.         push    di      ; (don't count on BIOS preserving anything)
  38.  
  39.         mov     ax,13h  ;let the BIOS set standard 256-color
  40.         int     10h     ; mode (320x200 linear)
  41.  
  42.         mov     dx,SC_INDEX
  43.         mov     ax,0604h
  44.         out     dx,ax   ;disable chain4 mode
  45.         mov     ax,0100h
  46.         out     dx,ax   ;synchronous reset while switching clocks
  47.  
  48.         mov     dx,MISC_OUTPUT
  49.         mov     al,0e7h
  50.         out     dx,al   ;select 28 MHz dot clock & 60 Hz scanning rate
  51.  
  52.         mov     dx,SC_INDEX
  53.         mov     ax,0300h
  54.         out     dx,ax   ;undo reset (restart sequencer)
  55.  
  56.         mov     dx,CRTC_INDEX ;reprogram the CRT Controller
  57.         mov     al,11h  ;VSync End reg contains register write
  58.         out     dx,al   ; protect bit
  59.         inc     dx      ;CRT Controller Data register
  60.         in      al,dx   ;get current VSync End register setting
  61.         and     al,7fh  ;remove write protect on various
  62.         out     dx,al   ; CRTC registers
  63.         dec     dx      ;CRT Controller Index
  64.         cld
  65.         mov     si,offset CRTParms ;point to CRT parameter table
  66.         mov     cx,CRT_PARM_LENGTH ;# of table entries
  67. SetCRTParmsLoop:
  68.         lodsw           ;get the next CRT Index/Data pair
  69.         out     dx,ax   ;set the next CRT Index/Data pair
  70.         loop    SetCRTParmsLoop
  71.  
  72.         mov     dx,SC_INDEX
  73.         mov     ax,0f02h
  74.         out     dx,ax   ;enable writes to all four planes
  75.         mov     ax,SCREEN_SEG ;now clear all display memory, 8 pixels
  76.         mov     es,ax         ; at a time
  77.         sub     di,di   ;point ES:DI to display memory
  78.         sub     ax,ax   ;clear to zero-value pixels
  79.         mov     cx,8000h ;# of words in display memory
  80.         rep     stosw   ;clear all of display memory
  81.  
  82.         pop     di      ;restore C register vars
  83.         pop     si
  84.         pop     bp      ;restore caller's stack frame
  85.         ret
  86. _Set320x240Mode endp
  87.         end
  88.